package com.sangananitsolution.soapApi;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

public class AdduesrAsyntask extends AsyncTask<String, String, Void> {
	private ProgressDialog pDialog;
	private final String URL = "http://garagesalesagogo.com.au/AuthenticationService.asmx?op=AddUser";
	private final String SOAP_ACTION = "http://tempuri.org/AddUser";
	private String TAG = "PGGURU";

	Context contextadd;
	String addUserfistname, addlastname, addemailaddress, addpassword,
			addphone, addcountry;

	public AdduesrAsyntask(String firstname, String lastname,
			String emailaddress, String password, String phone, String counrty) {
		// here all variable declartion will happen
		// this.contextadd=context;
		addUserfistname = firstname;
		addlastname = lastname;
		addemailaddress = emailaddress;
		addpassword = password;
		addphone = phone;
		addcountry = counrty;

		
	}

	@Override
	protected Void doInBackground(String... params) {
		Log.i(TAG, "doInBackground");
		SoapObject adduser = null;
		SoapObject usrobj = null;
		SoapObject loactionobj = null;

		// Create request

		adduser = new SoapObject("http://tempuri.org/", "AddUser");

		usrobj = new SoapObject("http://tempuri.org/", "usr");
		usrobj.addProperty("EmailAddress", addemailaddress);
		usrobj.addProperty("Passsword", addpassword);
		usrobj.addProperty("FirstName", addUserfistname);
		usrobj.addProperty("LastName", addlastname);
		usrobj.addProperty("PhoneNumber", addphone);
		usrobj.addProperty("Country", addcountry);

		loactionobj = new SoapObject("http://tempuri.org/", "Location");
		loactionobj.addProperty("Longitude", "125.21");
		loactionobj.addProperty("Latitude", "202.2");
		usrobj.addSoapObject(loactionobj);

		usrobj.addProperty("UserImage", "nkndnd");
		usrobj.addProperty("FacebookId", "njns442");
		adduser.addSoapObject(usrobj);

		// Create envelope
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;
		// Set output SOAP object
		envelope.setOutputSoapObject(adduser);
		envelope.implicitTypes = true;
		// Create HTTP call object
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
		SoapObject adduesrResponseobj = null;
		SoapObject adduesrResultobj = null;
		SoapObject userdateobj = null;
		SoapObject locationobj = null;

		try {
			// Invole web service
			androidHttpTransport.call(SOAP_ACTION, envelope);
			// Get the response

			adduesrResponseobj = (SoapObject) envelope.bodyIn;
			adduesrResultobj = (SoapObject) adduesrResponseobj.getProperty(0);
			String issuccess = adduesrResultobj
					.getPropertyAsString("IsSuccess");
			String message = adduesrResultobj.getPropertyAsString("Message");
			userdateobj = (SoapObject) adduesrResultobj.getProperty("UserData");
			String emailaddress = userdateobj
					.getPropertyAsString("EmailAddress");

			String firstbane = userdateobj.getPropertyAsString("FirstName");

			Log.i(TAG, issuccess);
			Log.i(TAG, message);
			Log.i(TAG, emailaddress);
			Log.i(TAG, firstbane);

		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}

	@Override
	protected void onPreExecute() {
		Log.i(TAG, "onPreExecute");
		// Showing progress dialog
		/*
		 * pDialog = new ProgressDialog(contextadd);
		 * pDialog.setMessage("Please wait for match List...");
		 * pDialog.setCancelable(false); pDialog.show();
		 */

	}

	@Override
	protected void onProgressUpdate(String... values) {
		Log.i(TAG, "onProgressUpdate");

	}

	@Override
	protected void onPostExecute(Void result) {
		Log.i(TAG, "onPostExecute");

	}

}
